package de.hs.rm;

import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.ImageView;

public class BHModeRemoteActivity  extends Activity {
	
	private BHMainApplication mainApp= null;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);
    	prepareImages();
    	Drawable bgImage = getResources().getDrawable(R.drawable.remotebackground);
        bgImage.setAlpha(30);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        requestWindowFeature(Window.FEATURE_NO_TITLE);        
        setContentView(R.layout.moderemote);
        
        mainApp = (BHMainApplication)this.getApplicationContext();
        
        ImageView ivRemoteUp = (ImageView) findViewById(R.id.remoteUp);
        ImageView ivRemoteTux = (ImageView) findViewById(R.id.remoteTux);
        ImageView ivRemoteDown = (ImageView) findViewById(R.id.remoteDown);
        
        ivRemoteUp.setOnClickListener(
    	    new OnClickListener() {
    	    		@Override
    	    		public void onClick(View v) {
    	    			int msg = KeyboardKeys.VK_UP.keyCode;
    	    			mainApp.sendBTMessage("keyboard:keydown:xA" + msg + "xE");
    	    			mainApp.sendBTMessage("keyboard:keyup:xA" + msg + "xE");
    	    		}
    	    	}
            );
        ivRemoteDown.setOnClickListener(
    	    new OnClickListener() {
    	    		@Override
    	    		public void onClick(View v) {
    	    			int msg = KeyboardKeys.VK_DOWN.keyCode;
    	    			mainApp.sendBTMessage("keyboard:keydown:xA" + msg + "xE");
    	    			mainApp.sendBTMessage("keyboard:keyup:xA" + msg + "xE");
    	    		}
    	    	}
            );
        ivRemoteTux.setOnClickListener(
    	    new OnClickListener() {
    	    		@Override
    	    		public void onClick(View v) {
    	    			String msg = "supertuxkart";
    	    			mainApp.sendBTMessage("remote:script:" + msg);
    	    		}
    	    	}
            );
    }
    
    private void prepareImages()
    {
    	ImageConverter.decodeSampledBitmapFromResource(getResources(), R.drawable.tuxicon, 200, 200);
    	ImageConverter.decodeSampledBitmapFromResource(getResources(), R.drawable.arrowupgreen, 200, 200);
    	ImageConverter.decodeSampledBitmapFromResource(getResources(), R.drawable.arrowdowngreen, 200, 200);
    }
}
